var PATH_PREFIX ="";

function setPathPrefix(path){
	PATH_PREFIX =  path;
}
$(function() {
	// 给select2组件加载样式
	WASP_WIDGET.initializeSelectStyle();
	WASP_WIDGET.triggerDateStyleWithYMD("#beginDateNew");
	WASP_WIDGET.triggerDateStyleWithYMD("#endDateNew");
	WASP_WIDGET.triggerPrdInfoSelect("productIdNew");
	// 注册清空事件
    WASP_WIDGET.registerResetClearEvent();
    WASP_WIDGET.triggerCustInfoSelect("custNoNew");
    WASP_WIDGET.triggerDictionarySelect("receiveType","RECEIVE_CATEGORY");
});

var $prdReceiveList = $('#prdReceiveList');

$(function() {
	$prdReceiveList.jqGrid({   
		url:PATH_PREFIX + 'prdReceiveDetailListPage.do', 
		/*caption:'产品收款明细列表<button type="button" class="btn btn-default btn-sm btn-small btn-fullscreen" title="" tabindex="-1"><i class="fa fa-arrows-alt icon-fullscreen"></i></button>',*/  
		datatype: "json",
		colNames:["id", "资金日期","收款账号","账号类型","产品名称","收款金额","收款状态","付款账号","付款人姓名","订单类型","账户余额"],        
		colModel:[  { name: 'receiveId', index: 'receiveId', key: true, hidden:true },       
		            { name: 'capitalDate', index: 'capitalDate', width: 30, resizable: true, sortable: false },
		            { name: 'receiveAcco', index: 'receiveAcco', width: 50, resizable: true, sortable: false },
		            { name: 'accountType', index: 'accountType', width: 30, resizable: true, sortable: false },
		            { name: 'productName', index: 'productName', width: 30, resizable: true, sortable: false },
		            { name: 'receiveAmount', index: 'receiveAmount', width: 50, resizable: true, sortable: false },
		            { name: 'receiveStatus', index: 'receiveStatus', width: 30, resizable: true, sortable: false },
		            { name: 'payerAcco', index: 'payerAcco', width: 50, resizable: true, sortable: false },
		            { name: 'payerName', index: 'payerName', width: 50, resizable: true, sortable: false },
		            { name: 'indentType', index: 'indentType', width: 30, resizable: true, sortable: false },
		            { name: 'accountBalance', index: 'accountBalance', width: 50, resizable: true, sortable: false }
				  ],
		rowNum: 20,
        rowList: [20, 30, 50],
        rownumbers: true,
        rownumWidth: 50,
        postData: {},
        prmNames: { search: "search", page: "pageNo", rows: "limit" },
        height: 'auto',
        width: false,
        autowidth:true,
        editurl: '',
        viewrecords: true,
        cellEdit: false,
        shrinkToFit: true,
        grouping: false,
        jsonReader: {
            root: "items", //结果集
            records: "total", //总记录数 
            total: "pageCount", //总页数
            page: "pageNo", //当前页 
            repeatitems: false // (4) 
        },  
		multiselect:false,
		pager: "#prdReceiveListPage",						
		viewrecords: true,
		hidegrid: false, 
		gridComplete: function(){
			var ids = $prdReceiveList.jqGrid('getDataIDs');
			for(var i = 0;i < ids.length;i++){
				var rowId = ids[i];
				$prdReceiveList.jqGrid('setRowData', ids[i]);
			}	
		}
	});
	$prdReceiveList.navGrid('#prdReceiveListPage',{edit:false,add:false,del:false,search:false,refreshstate:'current'});
	$prdReceiveList.jqGrid('setFrozenColumns');
	jqGridResize($prdReceiveList);
});

//绑定回车事件,查询
$("body").keypress(function(event){
	var key = event.which;
	if(key == "13"){
		queryByCondtion(true);
	}
});


function queryByCondtion(flag) {
	var beginDateNew = $.trim($("#beginDateNew").val());   
	var endDateNew   = $.trim($("#endDateNew").val());   
	var productIdNew = $.trim($("#productIdNew").val()); 
	var custNoNew    = $.trim($("#custNoNew").val()); 
	var receiveType = $.trim($("#receiveType").val()); 
	var postData = $prdReceiveList.jqGrid("getGridParam", "postData");
    $.extend(postData, {
        'sp[beginDate]':beginDateNew,
        'sp[endDate]':endDateNew,
        'sp[receiveType]':receiveType,
        'sp[productId]':productIdNew,
        'sp[custNo]':custNoNew
    });
    if (flag) {
    	$prdReceiveList.jqGrid("setGridParam",{"datatype": "json"}).trigger("reloadGrid", [{ page: 1 }]); //重新载入Grid表格
    } else {
    	$prdReceiveList.jqGrid("setGridParam",{"datatype": "json"}).trigger("reloadGrid"); //重新载入Grid表格
    }
}

